<template>
    <view class="container">
        <view  v-if="!searching">
            <view class="header">
                <view class="box" @click="onSearching">
                    <img src="../../../static/seek@2x.png" alt="" />
                    <text>搜索书籍</text>
                </view>
            </view>
            <view class="sub-container">
                <img
                    class="head-img"
                    src="../../../static/choicenness@2x.png"
                    alt=""
                />
                <view class="books-container">
                    <block :key="id" v-for="(item, index) in book">
                        <book
                            :img="item.image"
                            :title="item.title"
                            :author="item.author"
                            :fav_nums="item.fav_nums"
                        ></book>
                    </block>
                </view>
            </view>
        </view>
        <search v-if="searching" @close="close"></search>
    </view>
</template>

<script>
import { getHotList } from "@/api/book.js";
import book from "@/components/book/book.vue";
import search from "@/components/search/search.vue";
export default {
    components: {
        book,
        search
    },
    data () {
        return {
            book: [],
            searching: false
        };
    },
    created () {
        // 创建这个组件
        this.getHotList();

    },
    methods: {
        getHotList () {
            getHotList({
                // data的参数
                url: 'hot_list'
            }).then((res) => {
                this.book = res.data
            });
        },
        // 显示
        onSearching () {
            this.searching = true
        },

        // onCancel(){
        //     this.searching = false
        // },
        close () {
            this.searching = false
        },
    },
};
</script>

<style lang="scss" scoped>
.container {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.sub-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    background-color: #f5f5f5;
    margin-top: 100rpx;
}

.box {
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    border-radius: 50px;
    background-color: #f5f5f5;
    height: 68rpx;
    width: 700rpx;
    color: #999999;
}

.header {
    // 固定顶部
    position: fixed;
    background-color: #ffffff;
    height: 100rpx;
    width: 100%;
    border-top: 1px solid #f5f5f5;
    border-bottom: 1px solid #f5f5f5;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    box-shadow: 0 0 3px 0 #e3e3e3;
    z-index: 99;
}

.head-img {
    width: 106rpx;
    height: 34rpx;
    margin-top: 40rpx;
}
.box image {
    margin-right: 10px;
    width: 14px;
    height: 14px;
    margin-bottom: -2px;
}
.books-container {
    margin-top: 10rpx;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    // 两端分布
    justify-content: space-between;
    padding: 0 90rpx;
}

.books-container book {
    margin-bottom: 10rpx;
}
</style>
